import { Injectable } from '@nestjs/common';
// import { OrderEditDto, TokenInfo } from './order.dto'
import * as db from '../../../entity'
// import { Between } from 'typeorm';
import * as dateFns from 'date-fns'
// import { serverCode } from '../../../tool/server.code'

@Injectable()
export class ManagerOrderService {
    // constructor(private readonly) { }

    async getList(orderGet) {
        const pageIndex = orderGet.data.pageIndex ? orderGet.data.pageIndex : 1;
        const lists = await db.Order.find({
            order: {
                order_id: "DESC"
            },
            skip: (pageIndex - 1) * 10,
            take: 10,
        })
        const list = await Promise.all(lists.map(async it => {
            const findUser = await db.UserAccount.findOne({
                where: {
                    user_id: it.user_id
                }
            })
            return {
                id: it.order_id,
                name: it.name,
                mobile: findUser ? findUser.mobile : '',
                city: it.city,
                lendLimit: it.lend,
                lendTime: it.time_limit,
                purpose: it.purpose,
                worth: it.worth,
                income: it.income,
                incomeType: it.income_type,
                socialInsurance: it.social_insurance,
                accumulationFund: it.accumulation_fund,
                workYear: it.work_year,
                house: it.house,
                car: it.car,
                status: it.status,
                createTime: dateFns.format(it.create_time, 'YYYY-MM-DD HH:mm:ss')
            }
        }))
        const count = await db.Order.count({})
        const totalPage = Math.ceil(count / 10);
        return { data: { list, totalPage } }
    }
}